package com.janyo.soongo;


import android.app.Activity;
import android.app.FragmentManager;
import android.app.LoaderManager;
import android.app.ActionBar.LayoutParams;
import android.content.ContentResolver;
import android.content.Context;
import android.content.CursorLoader;
import android.content.Intent;
import android.content.Loader;
import android.database.Cursor;
import android.graphics.drawable.GradientDrawable.Orientation;
import android.opengl.Visibility;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TextView;

public class DiscoverActivity extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
		setContentView(R.layout.activity_discover);
		getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_web);
		
		ImageView btnBack=(ImageView)findViewById(R.id.imgBack);
		btnBack.setOnClickListener(new View.OnClickListener() {					
			@Override
			public void onClick(View v) {
				finish();
			}
		});
		TextView txtOver=(TextView)findViewById(R.id.txtOver);
		txtOver.setVisibility(View.INVISIBLE);
		
		// Inflate your view
		String inflater = Context.LAYOUT_INFLATER_SERVICE;
		LayoutInflater li;
		li = (LayoutInflater)getSystemService(inflater);
		LinearLayout llRoot=(LinearLayout)findViewById(R.id.llyRoot);
	
		Intent _Intent=getIntent();
		String tid=_Intent.getStringExtra("taskID");
		ContentResolver _cContentResolver=getContentResolver();
		soogoTaskBuilder _sBuilder=new soogoTaskBuilder();
		SoogoTask _sSoogoTask= _sBuilder.getSoogoTaskByID(_cContentResolver,tid);		     
		TextView txttaskName=(TextView)findViewById(R.id.txtTaskName);
		txttaskName.setText(_sSoogoTask.name);		   
		TextView txtPrice=(TextView)findViewById(R.id.txtPrice);
		txtPrice.setText(_sSoogoTask.newTotalMoney.toString());
		if (_sSoogoTask.Goods!=null) {
			for (int i = 0; i <_sSoogoTask.Goods.size(); i++) {
				LinearLayout llTemp=new LinearLayout(this);
				//llTemp.setOrientation(LinearLayout.VERTICAL);
				li.inflate(R.layout.fragment_discover, llTemp,true);
				TaskGoodsInfo  _TaskGoodsInfo=_sSoogoTask.Goods.get(i);

				TextView  txtGoodsName=(TextView)llTemp.findViewById(R.id.txtGoodsName);
				txtGoodsName.setText(_TaskGoodsInfo.goodsName);
				//TextView txtQuantity=(TextView)llTemp.findViewById(R.id.txtQuantity);
				//txtQuantity.setText(_TaskGoodsInfo.Num);
				TextView txtSumMoney=(TextView)llTemp.findViewById(R.id.txtSumMoney);
				txtSumMoney.setText(String.valueOf(_TaskGoodsInfo.price*_TaskGoodsInfo.Num));
				//TextView txtSite=(TextView)llTemp.findViewById(R.id.txtSite);
				TextView txtNowPrice=(TextView)llTemp.findViewById(R.id.txtNowPrice);
				txtNowPrice.setText(String.valueOf(_TaskGoodsInfo.price));
				int no=1;
				if (_sSoogoTask.NewDiscover!=null&&_sSoogoTask.NewDiscover.size()>0) {
					for (int j = 0; j <_sSoogoTask.NewDiscover.size(); j++) {
						if(no>3)break;
						DiscoverEnty _DiscoverEnty=_sSoogoTask.NewDiscover.get(j);
						if (_DiscoverEnty.GoodsID.equals(_TaskGoodsInfo.goodsID)) {

							int resID = getResources().getIdentifier(getPackageName()+":id/txtOtherName"+no , null,null);
							TextView txtOtherName=(TextView)llTemp.findViewById(resID);
							txtOtherName.setText(_DiscoverEnty.shop);
							resID = getResources().getIdentifier(getPackageName()+":id/txtOtherPrice"+no , null,null);
							TextView txtOtherPrice=(TextView)llTemp.findViewById(resID);
							txtOtherPrice.setText(String.valueOf(_DiscoverEnty.Price));
							resID = getResources().getIdentifier(getPackageName()+":id/txtDiffPrice"+no , null,null);
							TextView txtDiffPrice=(TextView)llTemp.findViewById(resID);
							txtDiffPrice.setText(String.valueOf((_TaskGoodsInfo.price- _DiscoverEnty.Price)*_TaskGoodsInfo.Num));
							no++;

						}
					}
				}
				else {
					
					TableLayout _tTableLayout=(TableLayout)llTemp.findViewById(R.id.tbNewDis);
					LinearLayout _llFragment=(LinearLayout)llTemp.findViewById(R.id.llFragment);
					if(_llFragment!=null&&_tTableLayout!=null)_llFragment.removeView(_tTableLayout);
					
				}
				//  TextView =(TextView)llTemp.findViewById(R.id.);

				llRoot.addView(llTemp);
			}

		}

		//				   TextView txttaskName=(TextView)findViewById(R.id
		//						   TextView txttaskName=(TextView)findViewById(R.id


	}

	@Override
	protected void onResume() {
		super.onResume();
	}
	
}
